﻿/*
 *  XTL - XNA Tool Library, a collection with usefull XNA classes
 * 
 *  Copyright (C) 2010 Sebastian Schäfer
 * 
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; version 2 of the License.
 *  
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;

namespace XTL.Input
{
    /// <summary>
    /// the XNAStateKeyboard is derived from the generic state manager and offers general key-based routines
    /// </summary>
    public class XNAStateKeyboard : XStateManager<KeyboardState>
    {
        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="state">The keyboard state</param>
        public XNAStateKeyboard(KeyboardState state)
            : base(state)
        {
        }

        /// <summary>
        /// Pseudo KeyDown Event: down in current and up in old state?
        /// </summary>
        /// <param name="k">Key</param>
        /// <returns>((stateCurrent.IsKeyDown(k)) and (stateOld.IsKeyUp(k)))</returns>
        public bool KeyDown(Keys k)
        {
            return ((stateCurrent.IsKeyDown(k)) && (stateOld.IsKeyUp(k)));
        }

        /// <summary>
        /// pseudo KeyUp Event: up in current and down in old state?
        /// </summary>
        /// <param name="k">Key</param>
        /// <returns>((stateCurrent.IsKeyUp(k)) and (stateOld.IsKeyDown(k)))</returns>
        public bool KeyUp(Keys k)
        {
            return ((stateCurrent.IsKeyUp(k)) && (stateOld.IsKeyDown(k)));
        }

        /// <summary>
        /// down in current?
        /// </summary>
        /// <param name="k">Key</param>
        /// <returns>(stateCurrent.IsDown(k))</returns>
        public bool IsDown(Keys k)
        {
            return stateCurrent.IsKeyDown(k);
        }

        /// <summary>
        /// up in current?
        /// </summary>
        /// <param name="k">Key</param>
        /// <returns>(stateCurrent.IsKeyUp(k))</returns>
        public bool IsUp(Keys k)
        {
            return stateCurrent.IsKeyUp(k);
        }

        /// <summary>
        /// Returns true if left alt is down.
        /// </summary>
        public bool LeftAlt { get { return IsDown(Keys.LeftAlt); } }
        /// <summary>
        /// Returns true if left control is down.
        /// </summary>
        public bool LeftControl { get { return IsDown(Keys.LeftControl); } }
        /// <summary>
        /// Returns true if left shift is down.
        /// </summary>
        public bool LeftShift { get { return IsDown(Keys.LeftShift); } }
    }
}
